package controller;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/ABCServlet")
public class ABCServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String hobby;
	private String name;

  
    public ABCServlet() {
       System.out.println("执行get结构方法");
    }


	public void init(ServletConfig config) throws ServletException {
		System.out.println("执行get的init初始化方法");
	}

	
	public void destroy() {
		System.out.println("执行get的destroy销毁方法");
	}

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("执行get的doGet方法");
		System.out.println("项目部署路径" + request.getServletContext().getRealPath(""));
		System.out.println("执行get的doGet执行完毕");
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		setName(request.getParameter("name"));
		response.getWriter().append("<h1>你好!" + "name" + "</h1>");
		String[] hobbies = request.getParameterValues("hobby");
		if(hobbies !=null) {
			response.getWriter().append("<h2>爱你:</h2>");
			response.getWriter().append("<u1>");
			for (int i = 0; i < hobbies.length; i++) {
				setHobby(hobbies[i]);
				response.getWriter().append("<li>" + "name" + "</li>");
			}
			response.getWriter().append("</h1>");
		}
		System.out.println("执行get的doGet执行完毕");
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getHobby() {
		return hobby;
	}


	public void setHobby(String hobby) {
		this.hobby = hobby;
	}

}
